class Money implements Cloneable{
    public double m=12.5;

    @Override
    protected Object clone() throws CloneNotSupportedException {
        return super.clone();
    }
}
class Person implements Cloneable{
    public int age;
    public Money money=new Money();

    public void eat(){
        System.out.println("吃!");
    }
    @Override
    public String toString() {
        return "Person{" +
                "age=" + age +
                '}';
    }
    @Override
    protected Object clone() throws CloneNotSupportedException {
        Person tmp=(Person) super.clone();
        tmp.money=(Money) this.money.clone();
        return tmp;
    }
}
public class TestDemo {
    public static void main(String[] args)throws CloneNotSupportedException {
        Person person=new Person();
        Person person2=(Person) person.clone();
        System.out.println(person.money.m);
        System.out.println(person2.money.m);
        System.out.println("======================");
        person2.money.m=99.99;
        System.out.println(person.money.m);
        System.out.println(person2.money.m);
    }
    public static void main1(String[] args) throws CloneNotSupportedException {
        Person person=new Person();
        person.age=99;
        Person person2=(Person) person.clone();
        System.out.println(person2);
        System.out.println("===================");
        person2.age=199;
        System.out.println(person);
        System.out.println(person2);
    }

}




































